package org.example;

import com.springframework.t.person.User;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.InvocationTargetException;

public class TestUser {
    private Logger logger = LoggerFactory.getLogger(TestUser.class);
    @Test
    public void test01(){
//        加载spring配置文件，对象创建
        ApplicationContext context = new ClassPathXmlApplicationContext("com.springframework/t/bean.xml");
//        获取创建的对象
        User user = (User) context.getBean("user");
        System.out.println(user);
//        使用对像调用方法进行测试
        user.add();
//      手动写日志
        logger.info("日志执行了！");
    }
    @Test
    public void test02() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//        获取类Class对象
        Class clazz = Class.forName("com.springframework.t.person.User");
        System.out.println(clazz);
//        调用方法创建对象
        User user = (User)clazz.getDeclaredConstructor().newInstance();
        user.add();
    }
}
